package com.ruoyi.qymlxin.controller;

import java.util.List;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.qymlxin.domain.ISysUserRole;
import com.ruoyi.qymlxin.service.IISysUserRoleService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 用户角色Controller
 * 
 * @author qymlxin
 * @date 2022-05-03
 */
@RestController
@RequestMapping("/product/userRole")
public class ISysUserRoleController extends BaseController
{
    @Autowired
    private IISysUserRoleService iSysUserRoleService;

    /**
     * 查询用户角色列表
     */
    @GetMapping("/list")
    public TableDataInfo list(ISysUserRole iSysUserRole)
    {
        startPage();
        List<ISysUserRole> list = iSysUserRoleService.selectISysUserRoleList(iSysUserRole);
        return getDataTable(list);
    }

    /**
     * 导出用户角色列表
     */
    @Log(title = "用户角色", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(ISysUserRole iSysUserRole)
    {
        List<ISysUserRole> list = iSysUserRoleService.selectISysUserRoleList(iSysUserRole);
        ExcelUtil<ISysUserRole> util = new ExcelUtil<ISysUserRole>(ISysUserRole.class);
        return util.exportExcel(list, "用户角色数据");
    }

    /**
     * 获取用户角色详细信息
     */
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(iSysUserRoleService.selectISysUserRoleById(id));
    }

    /**
     * 新增用户角色
     */
    @Log(title = "用户角色", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ISysUserRole iSysUserRole)
    {
        return toAjax(iSysUserRoleService.insertISysUserRole(iSysUserRole));
    }

    /**
     * 修改用户角色
     */
    @Log(title = "用户角色", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ISysUserRole iSysUserRole)
    {
        return toAjax(iSysUserRoleService.updateISysUserRole(iSysUserRole));
    }

    /**
     * 删除用户角色
     */
    @Log(title = "用户角色", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(iSysUserRoleService.deleteISysUserRoleByIds(ids));
    }
}
